/*     */ package xin.petstore.framework.cas.session.redis;
/*     */ 
/*     */ import java.util.Set;
/*     */ import redis.clients.jedis.Jedis;
/*     */ import redis.clients.jedis.JedisPool;
/*     */ import redis.clients.jedis.JedisPoolConfig;
/*     */ 
/*     */ public class RedisManager
/*     */ {
/*  11 */   private String host = "127.0.0.1";
/*     */ 
/*  13 */   private int port = 6379;
/*     */ 
/*  16 */   private int expire = 0;
/*     */ 
/*  19 */   private int timeout = 0;
/*     */ 
/*  21 */   private String password = "";
/*     */ 
/*  23 */   private static JedisPool jedisPool = null;
/*     */ 
/*     */   public void init()
/*     */   {
/*  33 */     if (jedisPool == null)
/*  34 */       if ((this.password != null) && (!"".equals(this.password)))
/*  35 */         jedisPool = new JedisPool(new JedisPoolConfig(), this.host, this.port, this.timeout, this.password);
/*  36 */       else if (this.timeout != 0)
/*  37 */         jedisPool = new JedisPool(new JedisPoolConfig(), this.host, this.port, this.timeout);
/*     */       else
/*  39 */         jedisPool = new JedisPool(new JedisPoolConfig(), this.host, this.port);
/*     */   }
/*     */ 
/*     */   public byte[] get(byte[] key)
/*     */   {
/*  51 */     byte[] value = (byte[])null;
/*  52 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/*  54 */       value = jedis.get(key);
/*     */     } finally {
/*  56 */       jedisPool.returnResource(jedis);
/*     */     }
/*  58 */     return value;
/*     */   }
/*     */ 
/*     */   public byte[] set(byte[] key, byte[] value)
/*     */   {
/*  68 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/*  70 */       jedis.set(key, value);
/*  71 */       if (this.expire != 0)
/*  72 */         jedis.expire(key, this.expire);
/*     */     }
/*     */     finally {
/*  75 */       jedisPool.returnResource(jedis);
/*     */     }
/*  77 */     return value;
/*     */   }
/*     */ 
/*     */   public byte[] set(byte[] key, byte[] value, int expire)
/*     */   {
/*  88 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/*  90 */       jedis.set(key, value);
/*  91 */       if (expire != 0)
/*  92 */         jedis.expire(key, expire);
/*     */     }
/*     */     finally {
/*  95 */       jedisPool.returnResource(jedis);
/*     */     }
/*  97 */     return value;
/*     */   }
/*     */ 
/*     */   public void del(byte[] key)
/*     */   {
/* 105 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/* 107 */       jedis.del(key);
/*     */     } finally {
/* 109 */       jedisPool.returnResource(jedis);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void flushDB()
/*     */   {
/* 117 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/* 119 */       jedis.flushDB();
/*     */     } finally {
/* 121 */       jedisPool.returnResource(jedis);
/*     */     }
/*     */   }
/*     */ 
/*     */   public Long dbSize()
/*     */   {
/* 129 */     Long dbSize = Long.valueOf(0L);
/* 130 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/* 132 */       dbSize = jedis.dbSize();
/*     */     } finally {
/* 134 */       jedisPool.returnResource(jedis);
/*     */     }
/* 136 */     return dbSize;
/*     */   }
/*     */ 
/*     */   public Set<byte[]> keys(String pattern)
/*     */   {
/* 145 */     Set keys = null;
/* 146 */     Jedis jedis = jedisPool.getResource();
/*     */     try {
/* 148 */       keys = jedis.keys(pattern.getBytes());
/*     */     } finally {
/* 150 */       jedisPool.returnResource(jedis);
/*     */     }
/* 152 */     return keys;
/*     */   }
/*     */ 
/*     */   public String getHost() {
/* 156 */     return this.host;
/*     */   }
/*     */ 
/*     */   public void setHost(String host) {
/* 160 */     this.host = host;
/*     */   }
/*     */ 
/*     */   public int getPort() {
/* 164 */     return this.port;
/*     */   }
/*     */ 
/*     */   public void setPort(int port) {
/* 168 */     this.port = port;
/*     */   }
/*     */ 
/*     */   public int getExpire() {
/* 172 */     return this.expire;
/*     */   }
/*     */ 
/*     */   public void setExpire(int expire) {
/* 176 */     this.expire = expire;
/*     */   }
/*     */ 
/*     */   public int getTimeout() {
/* 180 */     return this.timeout;
/*     */   }
/*     */ 
/*     */   public void setTimeout(int timeout) {
/* 184 */     this.timeout = timeout;
/*     */   }
/*     */ 
/*     */   public String getPassword() {
/* 188 */     return this.password;
/*     */   }
/*     */ 
/*     */   public void setPassword(String password) {
/* 192 */     this.password = password;
/*     */   }
/*     */ }

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.cas.session.redis.RedisManager
 * JD-Core Version:    0.6.0
 */